package com.lsh.oms.api.model.order.create;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.lsh.base.lang.Exceptions;
import com.lsh.oms.api.common.annotation.ParamRequired;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Project Name: lsh-oms
 *
 * @author peter
 * @date 18/9/5
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Setter
@Getter
@NoArgsConstructor
@ToString
public class MisOrderHeadDTO {

    private Long specifiedOrderCode;

    /**
     * NORMAL: default value
     * AGGREGATE: 商城汇总SO创建订单
     */
    private String orderClass = "NORMAL";

    /**
     * 临采需求
     */
    private String orderCode;

    @ParamRequired
    private String misOrderNo;

    private String misParentOrderNo;

    private Integer orderType;
    @ParamRequired
    private Integer regionCode;

    //    @ParamRequired
    private String supplierGroupId;

    private String saleAreaCode;

    private Integer isInDmall;

    private Position position;

    @ParamRequired
    private Long userCode;

    @ParamRequired
    private Long addressCode;

    private Integer province;

    private Integer city;

    private Integer district;

    private Integer area;

    @ParamRequired
    private String addressInfo;

    @ParamRequired
    private Integer orderTime;

    @ParamRequired
    private Integer payType;

    private String isComment;

    @ParamRequired
    private Integer storageType;

    @ParamRequired
    private Long clientIp;
    /**
     * from_type
     */
    private Integer clientType;
    private String saleInfo;
    private String activityInfo;
    private String couponInfo;
    private String cashCouponInfo;
    @ParamRequired
    private BigDecimal originMoney;
    @ParamRequired
    private BigDecimal saledMoney;
    @ParamRequired
    private BigDecimal placedMoney;
    @ParamRequired
    private BigDecimal goodsDiscountAmout;
    @ParamRequired
    private BigDecimal orderDiscountRate;
    @ParamRequired
    private BigDecimal orderDiscountAmout;
    @ParamRequired
    private BigDecimal ticketCouponAmout;
    @ParamRequired
    private BigDecimal cashCouponAmount;
    @ParamRequired
    private BigDecimal freight;
    @ParamRequired
    private BigDecimal floorAmount;
    @ParamRequired
    private BigDecimal expectPayAmount;

    private Integer isNewUser;
    @JSONField(name = "no_review")
    private Integer noReview;
    private String deviceId;

    private String ext;
    @ParamRequired
    private String marketName;

    private String adminName;
    @ParamRequired
    private String username;

    private String token;
    private String providerId;
    private String providerName;

    private String dcCode;

    @ParamRequired
    private BigDecimal skuCount;
    @ParamRequired
    private BigDecimal realSkuCount;
    @ParamRequired
    private BigDecimal discountedMoney;

    @JSONField(name = "remark")
    private String remarks;

    /**
     * 2019-2-18
     * poOrderFlag 1:预下单  2:确认（预下单）下单
     */
    private String poOrderFlag;
    /**
     * poId 进销存需要 （poOrderFlag  2:确认（预下单）下单 时 必传）
     */
    private String poId;
    /**
     * supplierCode 供商卡号（poOrderFlag  2:确认（预下单）下单 时 必传）
     */
    private String supplierCode;

    @ParamRequired
    private Long venderId;

    private List<MisOrderDetailDTO> details;

    public boolean aggregate() {
        return "AGGREGATE".equals(orderClass);
    }

    public Map<String, Object> extendedProperties() {
        if (StringUtils.isNotBlank(this.ext)) {
            try {
                return JSON.parseObject(this.ext);
            } catch (Exception e) {
                Exceptions.printStackTraceLineByLine(e);
            }
        }
        return Collections.emptyMap();
    }
}